<script setup>
import {useNote} from "@/stores/note.js";
import NoteModel from "@/components/Note/TimeLineComps/NoteModel.vue";

const Note = useNote()
const isLoadRls = ref(false) // 发布按钮是否正在加载

// 正在编辑的临时Note数据
const editNote = reactive({ noteContent: "", noteType: "todo" })

// myPost("/note/todos_all", { userToken: User.token }, todos => {
//   console.log(todos);
//   todoList.push(...todos)
//   // Note.tags.splice(Note.tags.indexOf(tag), 1);
// })


const releaseTodo = () => {
  // 先检查
  isLoadRls.value = true
  if (!editNote.noteContent) {
    ElMessage("你还没输入东西呢")
    return isLoadRls.value = false
  }
  
  console.log('🐔[ToDo.vue-isLoadRls:25] ', editNote)

  Note.releaseTodo(editNote, () => {
    // 清空editNote
    for (let key in editNote) delete editNote[key]
    editNote.noteContent = ''
    editNote.noteType = 'todo'
    // 发送按钮可用
    isLoadRls.value = false
  })

}

</script>

<template>
  <div>
    {{editNote.noteContent}}
    <el-input v-model="editNote.noteContent" @keyup.enter="releaseTodo" placeholder="帮你记住要做的事" size="large">
      <template #append>
        <el-button @click="releaseTodo">发布</el-button>
      </template>
    </el-input>

    <div>
      {{Note.todos}}
      <!--<NoteModel v-for="todo in Note.todos" :note="todo" :key="todo.noteId">-->

      <!--</NoteModel>-->
      <!--<div class="m-in-model" v-for="todo in Note.todos">{{ todo.noteContent }}</div>-->
    </div>
  </div>
</template>

<style scoped>
.m-in-model {
  margin-top: 10px;
}
</style>